import cv2
video=cv2.VideoCapture("landscape.avi") #打开视频
fps=video.get(cv2.CAP_PROP_FPS)     #获取帧速率
size=(int(video.get(cv2.CAP_PROP_FRAME_WIDTH)),
      int(video.get(cv2.CAP_PROP_FRAME_HEIGHT)))    #设置帧的大小
#生成MJPG-4视频编码格式的4字符代码
fource=cv2.VideoWriter_fourcc(*'XVID')
#创建VideoWriter类的对象
output=cv2.VideoWriter("out.avi",fource,fps,size)
while(video.isOpened()):
    retval,frame=video.read()       #读取每一帧
    if retval:
        output.write(frame)     #写入帧
    else:
        break
print("视频已保存")
video.release()     #释放资源
output.release()